<template>
  <a-row >
    <a-col>
      <a-card :bordered="false" style="margin-bottom: 10px">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form-model layout="inline" ref="ruleForm" :model="queryParam">
            <z-form-item :datas="fieldArr" :form="queryParam" :gutter="24" :toggle="toggleSearchStatus">
              <a-col :span="8" slot="submit-action">
                <a-space :size="6">
                  <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                  <a-button @click="onResetForm" icon="reload">重置</a-button>
                </a-space>
              </a-col>
            </z-form-item>
          </a-form-model>
        </div>
      </a-card>
      <a-card :bordered="false">
        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <div>
            <a-button type="primary" @click="clickPush(1)">预定培训</a-button>
          </div>
        </div>
<!--        <div>-->
<!--          <a-alert type="info" :showIcon="true">-->
<!--            <div slot="message">-->
<!--              截至目前，待预约<span style="color:#1890FF;"> {{ 11 }} </span>人，待访谈<span style="color:#1890FF;"> {{ 22-->
<!--              }} </span>人，已逾期<span style="color:#1890FF;"> {{ 22 }} </span>人-->
<!--            </div>-->
<!--          </a-alert>-->
<!--        </div>-->
        <!-- 表格展示 -->
        <div class="table-page-content">
          <z-table
            ref="table"
            rowKey="id"
            :showAlert="false"
            :showSelection="false"
            :loading="loading"
            :columns="columns"
            :dataSource="pageData"
            @selectedRow="onSelectedRow"
            @change="onTableChange"
          >
            <template slot="action" slot-scope="text, record">
              <a>查看</a>
              <a-divider type="vertical" />
              <a>编辑</a>
            </template>
          </z-table>
        </div>
        <!--弹窗区域-->
      </a-card>
    </a-col>
    <BookDetailModal ref="scheduleModalId" :title="bookTitle" :isUroscopy=isUroscopy @ok=onQuery />
  </a-row>
</template>

<script>
/*
/personnel/personnel
sjsk/specialist/personnel/personnel
 */
import { DisabledAuthFilterMixin } from '@/mixins/DisabledAuthFilterMixin'
import {listFor,listForm} from "@views/sjsk/modules/list";
import departTree from '../../modules/departTree'
import {trainList} from "@api/sjsk/specialist";
import BookDetailModal from "./BookingModal";
export default {
  components: { departTree,BookDetailModal },
  mixins: [DisabledAuthFilterMixin,listFor,listForm],
  data() {
    return {
      bookTitle:'培训预定',
      isUroscopy: true,
      labelCol: { span: 8 },
      wrapperCol: { span: 16 },
      rangePickerTime: [],
      show: false,
      closeTip: false,
      visible: false,
      handleModalBool: false,
      isDisabled: true,
      reloading: false,
      toggle: true,
      selectKeys: [],
      form: {},
      queryParam: {},
      handleModalTitle: null,
      /* 查询折叠 */
      toggleSearchStatus:true,
      fieldArr: [
        {label: '姓名', prop: 'suspectAccountName', tagType: 'input', span: 5},
        {label: '手机号', prop: 'suspectAccountNumber', tagType: 'input', span: 5},
        {label: '所属区域', prop: 'victimAccountType', tagType: 'dict-select', dictCode:'sex', span: 5, toggle: true},
      ],
      columns: [
        {
          title: '序号',
          dataIndex: 'order',
          width: 60,
          align: 'center',
          customRender: (text, record, index) => {
            return `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          }
        },
        {
          title: '培训主题',
          dataIndex: 'trainTopic',
          width: 60,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '开始时间',
          dataIndex: 'updateTime',
          width: 110,
          align: 'left',
          customRender: text => {
            return <j-ellipsis value={text} length={20} />
          }
        },
        {
          title: '结束时间',
          dataIndex: 'stopTime',
          width: 80,
          align: 'center'
        },
        {
          title: '培训地点',
          dataIndex: 'trainPlace',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '发起人',
          dataIndex: 'sponsor',
          width: 80,
          align: 'center'
        },
        {
          title: '参加人数',
          dataIndex: 'joinNumberPeople',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '状态',
          dataIndex: 'trainStatus',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '预定时间',
          dataIndex: 'reserveTime',
          width: 100,
          align: 'center',
          customRender: text => {
            return <j-ellipsis value={text} length={14} />
          }
        },
        {
          title: '操作',
          width: 120,
          align: 'center',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' },
        }
      ],
      pageFilter: {
        pageNo: 1,
        pageSize: 10
      },

    }
  },
  created() {},
  async mounted() {
    this.onQuery()
  },
  methods: {

    onQuery() {
      this.pageFilter.pageNo = 1
      this.refreshTable()
      // this.$refs.ruleForm.validate((valid) => {
      //   if (valid) {
      //     console.log(this.queryParam)
      //   } else {
      //     return false
      //   }
      // })
    },
    refreshTable() {
      let form = Object.assign({}, this.form, this.pageFilter)
      this.loading = true
      trainList(form)
        .then(res => {
          console.log(res)
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
            this.$refs.table.onClearRowKeys()
          } else {
            this.loading = false
          }
        })
        .catch(e => {
          this.loading = false
          this.$message.warn('请求失败！')
        })
    },
    // 弹窗成功接收
    modalOk(type) {
      this.onQuery()
    },
    getSelectedKeys(keys) {
      console.log(keys)
      this.$set(this.form, 'labelId', keys.join(','))
      this.onQuery()
    },
    // 新增
    clickPush(type) {
      if (type == 1) { //预约(突击尿检)
        this.$refs.scheduleModalId.show(1) //列表数据回填
      }
      if (type == 2) { //预约(常规尿检)
        this.$refs.scheduleModalId.show(2, record) //列表数据回填
      }
      if (type == 3) { //改约
        this.getYYdetail(record.id) //获取预约的数据并回填
      }
    },
    // 详情
    handleDetails(record) {
      this.handleModalTitle = '任务详情'
      this.$refs.intellDetailModalRef.show(record)
    },
    // 修改分组
    handleProups() {
      let selectList = this.$refs.table.getSelectedRows()
      let idList = selectList.map(v => v.id).filter(obj => obj !== null && obj !== undefined && obj !== '')
      this.$refs.groupsModalRef.edit(idList)
    },
    /** 重新加载组件 */
    reload() {
      this.reloading = true
      this.$nextTick(() => (this.reloading = false))
    },
    getTreeData(datas, id) {
      console.log(datas, id)
      console.log(id)
    },
    toggleBool(bool) {
      console.log(bool)
      this.toggle = bool
    }
  }
}
</script>
<style lang="less" scoped>
@import '~@assets/less/common.less';
</style>
